import { Controller, Get, Post } from '@nestjs/common';
import { RankingService } from './ranking.service';

@Controller('ranking')
export class RankingController {
  constructor(private readonly rankingService: RankingService) {}

  //获取文章周排行榜
  @Get('weekly')
  async getWeeklyRanking() {
    return await this.rankingService.getWeeklyViews();
  }

  // 手动触发周榜的更新
  @Post('updateWeekly')
  async updateWeeklyRanking() {
    await this.rankingService.handleCron();
    return { message: '周榜更新成功' };
  }

  // 手动触发月榜的更新
  @Post('updateMonthly')
  async updateMonthlyRanking() {
    await this.rankingService.handleMonthlyCron();
    return { message: '月榜更新成功' };
  }

  // 获取实时排行榜
  @Get('realTime')
  async getRealTimeRanking() {
    return await this.rankingService.getRealTimeRanking();
  }

  // 获取实时排行榜(缓存)
  @Get('withCache')
  async getRealTimeRankingWithCache() {
    return await this.rankingService.getRealTimeRankingWithCache();
  }

  //获取文章月排行榜
  @Get('monthly')
  async getMonthlyRanking() {
    return await this.rankingService.getMonthlyViews();
  }
}
